class_name Buff
extends Resource

@export var buff_id:String
@export var buff_name:String
@export_multiline var buff_desc:String
@export var buff_sprite:Texture2D
@export_range(0,120) var max_duration:float = 3
@export_range(0,10) var time_scale:float = 1
@export_range(0,StaticValue.INT_MAX) var max_level:int = 1
@export var buff_type:GameEnum.BuffType = GameEnum.BuffType.None
@export_flags("Tag0","Tag1") 
var buff_tag:int = 0
@export var conflict_resolution:GameEnum.BuffConflictResolution = GameEnum.BuffConflictResolution.Combine
@export var dispellable:bool = false
@export var demotion:int = -1
var cur_buff_agent:BuffComponent
var provider:Node
var inited:bool = false
var cur_level:int = 0:
	get:return cur_level
	set(value):
		var change_value:int = clamp(value,0,max_level) - cur_level
		on_level_changed.emit(change_value)
		cur_level += change_value
var residual_duration:float = 0

signal on_get_buff
signal on_lost_buff
signal on_update_buff
signal on_level_changed(change_value:int)
signal on_update_buff_list

func init_buff(provider:Node,buff_agent:BuffComponent):
	if inited:
		push_error("已初始化过！")
	elif buff_agent == null:
		push_error("Buff持有者不能为空")
	else:
		cur_buff_agent = buff_agent
		self.provider = provider
		inited = true
		if demotion < 0:
			demotion = max_level
		elif demotion == 0:
			max_duration = INF
